﻿Public Class ReportUT519
    Inherits System.Web.UI.Page

    Private Property DataSource As Data.DataTable
        Get
            Return Me.Session("datasourceut519")
        End Get
        Set(ByVal value As Data.DataTable)
            Me.Session("datasourceut519") = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
        Dim dteFrom As String = Nothing
        Dim dteTo As String = Nothing

        If StartDateFrom.Text <> "" Then dteFrom = Common.UtilityDateTime.ConvertDate(Me.StartDateFrom.Text).Value.AddYears(-543).ToString("dd/MM/yyyy")
        If StartDateTo.Text <> "" Then dteTo = Common.UtilityDateTime.ConvertDate(Me.StartDateTo.Text).Value.AddYears(-543).ToString("dd/MM/yyyy")

        DataSource = BL.Report.ReportUT519(dteFrom, dteTo, Me.ucPopupOfficer1.OfficerAppId, txtTelSuccess.Text.Trim, txtOfficerName.Text.Trim)

        Bind(0)
    End Sub

    Private Sub Bind(ByVal pageIndex As Integer)
        Me.gvList.DataSource = DataSource
        Me.gvList.PageIndex = pageIndex
        Me.gvList.DataBind()
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnReset.Click
        Me.Session.Remove("datasourceut519")
        Response.Redirect("ReportUT519.aspx", False)
    End Sub

    Private Sub gvList_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvList.PageIndexChanging
        Bind(e.NewPageIndex)
    End Sub

    Protected Sub btnExcel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExcel.Click
        If Me.DataSource Is Nothing OrElse Me.DataSource.Rows.Count = 0 Then
            Exit Sub
        End If

        Dim dt As DataTable = Me.DataSource
        dt.Columns.Add("OrderNo")
        Dim i As Integer = 0
        For Each dr As DataRow In dt.Rows
            i += 1
            dr("OrderNo") = i.ToString
        Next
        Common.Utility.ExportToSpreadsheet(gvList, dt, "OfficerAuditInfo")
    End Sub

    Public Shared Function OrderNuber() As String
        Return String.Empty
    End Function

End Class